package cn.edu.hqu.cst.lecture02_02.model;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
@Data
public class Comment {
    @NotBlank(message="评论内容不能为空")
    @Size(max=500, message="评论长度不能超过500个字符")
    private String content;
	private Movie movie;
    @NotNull(message="评分不能为空")
    @Min(value=1, message="评分至少为1")
    @Max(value=5, message="评分不能超过5")
    private Integer rating;

    private Long id;
    private Long movieId;

    private static List<Comment> comments = new ArrayList<>();

    static {
        // 添加一些初始评论
        comments.add(new Comment(1L, "Great movie!", 5, 1L));
        comments.add(new Comment(2L, "Not bad", 3, 1L));
        comments.add(new Comment(3L, "Could be better", 2, 2L));
    }

    public Comment() {}

    public Comment(Long id, String content, Integer rating, Long movieId) {
        this.id = id;
        this.content = content;
        this.rating = rating;
        this.movieId = movieId;
    }

    public static List<Comment> getCommentsByMovieId(Long movieId) {
        return comments.stream()
                .filter(comment -> comment.getMovieId().equals(movieId))
                .collect(Collectors.toList());
    }

    public static void addComment(Comment comment) {
        comment.setId((long) (comments.size() + 1)); // 简单的 ID 赋值逻辑
        comments.add(comment);
    }

    
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Integer getRating() {
        return rating;
    }

    public void setRating(Integer rating) {
        this.rating = rating;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getMovieId() {
        return movieId;
    }

    public void setMovieId(Long movieId) {
        this.movieId = movieId;
    }
}